package com.nuoniu.sibanyun.service.cms.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.cms.CmsProduct;
import com.nuoniu.sibanyun.mapper.cms.CmsProductMapper;
import com.nuoniu.sibanyun.service.cms.ICmsProductService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 网站产品 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2022-06-17
 */
@Service
public class CmsProductServiceImpl extends ServiceImpl<CmsProductMapper, CmsProduct> implements ICmsProductService {

    @Override
    public Page<CmsProduct> pageList(Page page, CmsProduct product) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("company_id", UserThreadLocal.get().getCompanyId());
        return page(page, wrapper);
    }

    @Override
    public void saveProduct(CmsProduct product) {
        if(product.getId() == null) {
            product.setCompanyId(UserThreadLocal.get().getCompanyId());
        }
        this.saveOrUpdate(product);
    }
}
